﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace OurMind.Controls.Connectors
{
    ///<summary>水平直线连接符。</summary>
    public class TestLineConnector : BaseConnector
    {
        protected override void OnRender(DrawingContext dc)
        {
            var renderSize = RenderSize;

            Point startPoint;
            Point endPoint;

            switch (Direction)
            {
                case ConnectorDirectionEnum.LeftBottomToRightTop:
                    startPoint = new Point(0 + LineMargin, renderSize.Height - LineMargin);
                    endPoint = new Point(renderSize.Width - LineMargin, 0d + LineMargin);
                    break;
                case ConnectorDirectionEnum.LeftTopToRightBottom:
                    startPoint = new Point(0 + LineMargin, 0d + LineMargin);
                    endPoint = new Point(renderSize.Width - LineMargin, renderSize.Height - LineMargin);
                    break;
                default:
                    throw new NotImplementedException();
            }

            var centerX = (startPoint.X + endPoint.X) / 2;
            var centerY = (startPoint.Y + endPoint.Y) / 2;


            //dc.DrawLine(LineBrush, startPoint, endPoint);
            var geo = Geometry.Parse($"M {startPoint.X} {startPoint.Y} C {centerX} {startPoint.Y} {centerX} {endPoint.Y} {endPoint.X} {endPoint.Y} ");

            //var geo = new StreamGeometry();
            //using(var ctx = streamgeo.Open())
            //{
            //    ctx.BeginFigure(startPoint, false, false);
            //    ctx.BezierTo(new Point(centerX, startPoint.Y), new Point(centerX, endPoint.Y), endPoint, true, false);
            //}

            // 贝塞尔曲线
            dc.DrawGeometry(null, LineBrush, geo);
        }
    }
}